﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Modbus.Utility;

namespace ModbusTestTool
{
    class ULongInv : BaseRegisterGeneric <Int32>
    {
        /// <summary>
        /// The actual internal value
        /// </summary>



        public ULongInv(string inParamName, int inRegister)
            : base(inParamName, inRegister)
        {
        }

        public override void getValue(ushort[] word)
        {
            byte[] all = BitConverter.GetBytes(m_result);
            word[this.baseRegister] = BitConverter.ToUInt16(all, 0);
            word[this.baseRegister + 1] = BitConverter.ToUInt16(all, 2);
            
        }
        

        public override int size { get { return 2; } }

        /// <summary>
        /// Pass in an array which represent a modbus range exampe 40000-49999 the function will extract value from array
        /// </summary>
        /// <param name="dataStore"></param>
        public override void setValue(ushort[] dataStore)
        {
            lock (lockVariable)
            {
                byte[] temp = new byte[4];
                temp[0] = BitConverter.GetBytes(dataStore[baseRegister + 1])[0];
                temp[1] = BitConverter.GetBytes(dataStore[baseRegister + 1])[1];
                temp[2] = BitConverter.GetBytes(dataStore[baseRegister])[0];
                temp[3] = BitConverter.GetBytes(dataStore[baseRegister])[1]; ;
                m_result = BitConverter.ToInt32(temp, 0);
                NotifyPropertyChanged("value");
            }
        }


    }
}
